#include "SPI.h"
#include "LPD8806.h"
#include "rastermap.h"
#include "program.h"

#define NUM_LEDS 78

#define W 5
#define H 16


int strip_map[W * H] = {
0,   29,  30,  55,  56,  //70,
1,   28,  31,  54,  57,  //71,
2,   27,  32,  53,  58,  //72,
3,   26,  33,  52,  59,  //73,
4,   25,  34,  51,  60,  //74,
5,   24,  35,  50,  61,  //75,
6,   23,  36,  49,  62,  //76,
7,   22,  37,  48,  63,  //77,
8,   21,  38,  47,  64,  //-1,
9,   20,  39,  46,  65,  //-1,
10,  19,  -1,  45,  66,  //-1,
11,  18,  -1,  44,  67,  //-1,
12,  17,  -1,  43,  68,  //-1,
13,  16,  -1,  42,  69,  //-1,
-1,  15,  -1,  41,  -1,  //-1,
-1,  14,  -1,  40,  -1,  //-1,
};

const int LPD_DPIN = 2;
const int LPD_CPIN = 3;

LpdRaster lights(NUM_LEDS, 1, LPD_DPIN, LPD_CPIN);
RasterMapper displayMapper(strip_map, &lights, W, H);
Raster& display = displayMapper;

Life<W, H> life;

const short DEFAULT_DIP_MAP[1] = {
  7
};

Switches switches(DEFAULT_DIP_MAP, 1);

ProgramSelector program_selector(
  &switches,
  Programs(
    &life,
    &life,
    NULL));

DoubleBuffer<W, H> main_program(program_selector);

void setup() {
  Serial.begin(38400);
  Serial.println("Begin initialization");
  randomSeed(analogRead(0));

  lights.Init();

  main_program.Reset(display);

  Serial.println("End initialization");
}

void loop() {
  if (main_program.DoLoop(0)) {
    lights.Show();
  }
  delay(10);  // Apparenly was executing to fast without this.
}



